namespace EyeSoft.Wpf.Facilities
{
	using System.Diagnostics;
	using System.Windows;

	using EyeSoft.Windows;

	public static class ApplicationExtensions
	{
		public static bool IsAlreadyRunning(this Application application, Process process = null)
		{
			return application.GetType().Assembly.IsAlreadyRunning(application.Shutdown, process);
		}

		public static SyncExecution Sync(this Application application)
		{
			return new SyncExecution(application);
		}

		public static AsyncExecution Async(this Application application)
		{
			return new AsyncExecution(application);
		}

		public static Window GetMainWindow(this Application application)
		{
			Window mainWindow = null;

			application.Sync().Execute(() => mainWindow = application.MainWindow);

			return mainWindow;
		}
	}
}